package bootload

import (
	"cabinet/pkg/global"
	"cabinet/pkg/log"
	"context"

	"github.com/redis/go-redis/v9"
)

// Redis 在中间件中初始化redis链接
func InitRedis() {
	client := redis.NewClient(&redis.Options{
		Addr:       global.Conf.Redis.Host,
		Username:   global.Conf.Redis.Username,
		Password:   global.Conf.Redis.Password,
		DB:         global.Conf.Redis.DB,
		MaxRetries: 1,
	})
	ctx := context.Background()
	_, err := client.Ping(ctx).Result()

	if err != nil {
		log.Log().Panic("连接Redis不成功", err)
	}

	global.Redis = client
}
